class Solution {//leetcode39——组合总合
private:
    void dfs(vector<int>& candidates,int path_sum,int pos){
        if(path_sum>_target) return;
        if(path_sum==_target) {
            ret.push_back(path);
            return;
        }
        for(int i=pos;i<candidates.size();i++){
            path.push_back(candidates[i]);
            dfs(candidates,path_sum+candidates[i],i);
            path.pop_back();
        }
    }
public:
    vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
        _target=target;
        dfs(candidates,0,0);
        return ret;
    }
private:
    vector<vector<int>> ret;
    int _target;
    vector<int> path;
};